package servlet.buyShopping;

import bean.Result;
import biz.AddressBiz;
import biz.BizException;
import com.google.gson.Gson;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "AddAdressServlet", value = "/AddAdressServlet.s")
public class AddAdressServlet extends HttpServlet {
    private AddressBiz biz = new AddressBiz();
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        final String receiverprovince = request.getParameter("receiverprovince");
        final String receiveraddress = request.getParameter("receiveraddress");
        final String receiverphone = request.getParameter("receiverphone");
        final String receivername = request.getParameter("receivername");
        final String uid = request.getParameter("uid");
        Result result;
        try {
            biz.addAddress(uid,receivername,receiverphone,receiverprovince,receiveraddress,null);
            result =new Result(1,"添加成功",null);
        } catch (BizException e) {
            e.printStackTrace();
            result =new Result(0,e.getMessage(),null);
        }
        final String json = new Gson().toJson(result);
        response.getWriter().append(json);
    }
}
